package demo9;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class test3 {
    public static void main(String[] args) {

        //获取当前的时间的Instant对象（标准对象）
        Instant now = Instant.now();
        System.out.println(now);

        //根据（秒、毫秒，纳秒）获取Instant对象
        Instant instant1 = Instant.ofEpochMilli(0L);
        System.out.println(instant1);

        Instant instant2 = Instant.ofEpochMilli(1L);
        System.out.println(instant2);

        Instant instant3 = Instant.ofEpochSecond(1l,1000000000L);

        //指定时区
        ZonedDateTime time = Instant.now().atZone(ZoneId.of("Asia/Shanghai"));
        System.out.println(time);

        //判断
        Instant instant4 = Instant.ofEpochMilli(0L);
        Instant instant5 = Instant.ofEpochMilli(1000L);

        //判断调用者代表的时间是否在参数表示时间的前面
        boolean result1 = instant4.isBefore(instant5);
        System.out.println(result1);
        //判断调用者代表的时间是否在参数表示时间的后面
        boolean result2 = instant4.isAfter(instant5);
        System.out.println(result2);

        //减少时间系列的方法
        Instant instant6 = Instant.ofEpochMilli(3000L);
        System.out.println(instant6);

        Instant instant7 = instant6.minusSeconds(1);
        Instant instant8 = instant6.plusSeconds(1);
        System.out.println(instant7);
        System.out.println(instant8);
    }
}
